<?php
$mysql_id = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($db, $mysql_id);
$sql="select zip,plaats from aquakm where km >=1 and km <= 50 order by plaats";
 
$res = mysql_query($sql, $mysql_id);
$tel=0;
while ($row = mysql_fetch_row($res)) {
	$km1tot50[$tel]= $row[0] . '$' . $row[1];
	$tel++;
}
mysql_free_result($res);
 
$sql="select zip,plaats from aquakm where km >=51 and km <= 120 order by plaats";
$res = mysql_query($sql, $mysql_id);
$tel=0;
while ($row = mysql_fetch_row($res)) {
	$km51tot120[$tel]= $row[0] . '$' . $row[1];
	$tel++;
}
mysql_free_result($res);

$sql="select zip,plaats from aquakm where km >=121 and km <= 200 order by plaats";
 
$res = mysql_query($sql, $mysql_id);
$tel=0;
while ($row = mysql_fetch_row($res)) {
	$km121tot200[$tel]= $row[0] . '$' . $row[1];
	$tel++;
}
mysql_free_result($res);

$sql="select zip,plaats from aquakm where km >=201 and km <= 280 order by plaats";
 
$res = mysql_query($sql, $mysql_id);
$tel=0;
while ($row = mysql_fetch_row($res)) {
	$km201tot280[$tel]= $row[0] . '$' . $row[1];
	$tel++;
}
mysql_free_result($res);

 
$sql="select zip,plaats from aquakm where km >=281 and km <= 350 order by plaats";
 
$res = mysql_query($sql, $mysql_id);
$tel=0;
while ($row = mysql_fetch_row($res)) {
	$km281tot350[$tel]= $row[0] . '$' . $row[1];
	$tel++;
}
mysql_free_result($res);

$getal[1] = count($km1tot50);
$getal[2] = count($km51tot120);
$getal[3] = count($km121tot200);
$getal[4] = count($km201tot280);
$getal[5] = count($km281tot350);

sort($getal);
$hoogste = $getal[4];

?>
<table align="center" border="1" width="99%">
<tr><td colspan="10" bgcolor="orange"><strong><div style="text-align: center">Zones</div></strong></td></tr>
<tr>
<td colspan="2" class="center" bgcolor="#e6ef85">1-50 km</td>
<td colspan="2" class="center" bgcolor="white">51-120 km</td>
<td colspan="2" class="center" bgcolor="#f6bea2">121-200 km</td>
<td colspan="2" class="center" bgcolor="#92e3ef">201-280 km</td>
<td colspan="2" class="center" bgcolor="#ff6446">281-350 km</td>
</tr>
<tr>
<?php
$routine = 0;
while($routine < $hoogste) {
	 if(empty($km1tot50[$routine])) {$km1[0] = "&nbsp;";$km1[1]="&nbsp;";} else {$km1 = explode("$", $km1tot50[$routine]);}
	 if(empty($km51tot120[$routine])) {$km2[0] = "&nbsp;";$km2[1]="&nbsp;";} else {$km2 = explode("$", $km51tot120[$routine]);}
	 if(empty($km121tot200[$routine])) {$km3[0] = "&nbsp;";$km3[1]="&nbsp;";} else {$km3 = explode("$", $km121tot200[$routine]);}
	 if(empty($km201tot280[$routine])) {$km4[0] = "&nbsp;";$km4[1]="&nbsp;";} else {$km4 = explode("$", $km201tot280[$routine]);}
	 if(empty($km281tot350[$routine])) {$km5[0] = "&nbsp;";$km5[1]="&nbsp;";} else {$km5 = explode("$", $km281tot350[$routine]);}
	 
	 echo "<td class='zones' bgcolor='#e6ef85'>$km1[0]</td><td class='zones' bgcolor='#e6ef85'><a href='zoneupdate.php?zone=aquakm&stad=$km1[1]' class='zones'>$km1[1]</a></td>\n";
	 echo "<td class='zones'bgcolor='white'>$km2[0]</td><td class='zones' bgcolor='white'><a href='zoneupdate.php?zone=aquakm&stad=$km2[1]' class='zones'>$km2[1]</a></td>\n";
	 echo "<td class='zones' bgcolor='#f6bea2'>$km3[0]</td><td class='zones' bgcolor='#f6bea2'><a href='zoneupdate.php?zone=aquakm&stad=$km3[1]' class='zones'>$km3[1]</a></td>\n";
	 echo "<td class='zones' bgcolor='#92e3ef'>$km4[0]</td><td class='zones' bgcolor='#92e3ef'><a href='zoneupdate.php?zone=aquakm&stad=$km4[1]' class='zones'>$km4[1]</a></td>\n";
	 echo "<td class='zones' bgcolor='#ff6446'>$km5[0]</td><td class='zones' bgcolor='#ff6446'><a href='zoneupdate.php?zone=aquakm&stad=$km5[1]' class='zones'>$km5[1]</a></td>\n";
	 echo "</tr><tr>";	 
$routine++;	
}
?>
</table>
